#include "bench.hpp"

void sync_test(size_t thread_num,size_t msg_len,size_t msg_count)
{
    static int num=1;
    std::string  logger_name="sync_bench_logger"+std::to_string(num++);
    std::string file="./logfile/"+logger_name+".log";
    INFO("********************************************");
    INFO("同步日志测试: %d threads, %d messages",thread_num,msg_count);

    std::unique_ptr<logs::LoggerBuilder> builder(new logs::GlobalLoggerBuilder());
    builder->buildLoggerName(logger_name);
    builder->buildLoggerType(logs::LoggerType::LOGGER_SYNC);
    builder->buildSink<logs::FileSink>(file);
    builder->buildLoggerLevel(logs::LogLevel::value::DEBUG);
    builder->buildFormatter("%m%n");
    builder->build();
    logs::bench(logger_name,thread_num,msg_len,msg_count);
    INFO("********************************************");
}

void async_test(size_t thread_num,size_t msg_len,size_t msg_count)
{
    static int num=1;
    std::string  logger_name="async_bench_logger"+std::to_string(num++);
    std::string file="./logfile/"+logger_name+".log";
    INFO("********************************************");
    INFO("异步日志测试: %d threads, %d messages",thread_num,msg_count);

    std::unique_ptr<logs::LoggerBuilder> builder(new logs::GlobalLoggerBuilder());
    builder->buildLoggerName(logger_name);
    builder->buildLoggerType(logs::LoggerType::LOGGER_ASYNC);
    builder->buildSink<logs::FileSink>(file);
    builder->buildLoggerLevel(logs::LogLevel::value::DEBUG);
    builder->buildFormatter("%m%n");
    builder->buildEnableUnSafeAsync();
    builder->build();
    logs::bench(logger_name,thread_num,msg_len,msg_count);
    INFO("********************************************");
}

void bench_test()
{
    // sync_test(1,10,5000000);
    // sync_test(3,10,5000000);
    async_test(1,10,5000000);
    async_test(3,10,5000000);
}

int main()
{
    bench_test();
    return 0;
}